﻿Imports Microsoft.VisualBasic
Imports System.Data

<System.ComponentModel.DataObjectAttribute(True)> _
Public Class BLL_AddAward

    Public Sub New()
        ' 
        ' TODO: 在此加入建構函式的程式碼 
        ' 
    End Sub

    'SELECT 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.[Select])> _
    Public Function BLL_Select(ByVal AwardID As Integer) As DataTable

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("SELECT A.AwardID,A.VolunteerID,B.VolunteerName,A.AwardReason ")
        sql.AppendFormat("FROM AwardRecord A ")
        sql.AppendFormat("LEFT Join Volunteer B on A.VolunteerID = B.VolunteerID ")
        sql.AppendFormat("WHERE B.Active in ('2','Y') AND A.AwardID={0} ", AwardID)

        Return dat.GetData(sql)

    End Function

    'Update 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update)> _
    Public Function BLL_Update(ByVal AwardReason As String, ByVal original_AwardID As Integer, ByVal original_VolunteerID As String) As Integer

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.AppendFormat("UPDATE AwardRecord SET AwardReason='{0}' WHERE AwardID={1}  and VolunteerID='{2}'; ", AwardReason, original_AwardID, original_VolunteerID)

            dat.AccData(sql)

            scope.Complete()

            Return 1

        End Using

    End Function

    'Delete 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete)> _
    Public Sub BLL_Delete(ByVal original_AwardID As Integer, ByVal original_VolunteerID As String)

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            sql.AppendFormat("DELETE AwardRecord WHERE AwardID={0}  and VolunteerID='{1}'; ", original_AwardID, original_VolunteerID)

            dat.AccData(sql)

            scope.Complete()

        End Using

    End Sub

End Class
